package com.google.code.greenplate;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.RadioGroup.OnCheckedChangeListener;

public class RideResponse extends Activity {
	
	private RadioGroup mRideResponseGroup;
	private RadioButton mRideResponseButton;
	private TextView mTextView;
	private Button mPostRideButton;
	
	private class RadioGroupListener implements OnCheckedChangeListener {
		public void onCheckedChanged(RadioGroup radioGroup, int idOfSelectedRadioButton) {
			if (idOfSelectedRadioButton != 1) {
				mRideResponseButton = (RadioButton) findViewById(idOfSelectedRadioButton);
				mTextView.setText(getString(R.string.selection) + " " + mRideResponseButton.getText());
			
	            Intent intent = new Intent();
	            if (idOfSelectedRadioButton == R.id.bus) {	            	
	            	intent.setClass(RideResponse.this, RideList.class);	            	
	            }
	            else {
	            	intent.setClass(RideResponse.this, RideList2.class);
	            }
	            startActivity(intent);
			}
		}
	}
		
	private class PostarideButtonListener implements OnClickListener {
		public void onClick(View v) {
            Intent intent = new Intent();
            intent.setClass(RideResponse.this, LiveRides.class);
            startActivity(intent);
		}
	}
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ride_response);
        setWidgetReferences();
        addWidgetListeners();
    }
    
    private void setWidgetReferences() {
    	mRideResponseGroup = (RadioGroup) findViewById(R.id.rideResponse);
    	mTextView = (TextView) findViewById(R.id.selection);
    	mPostRideButton = (Button) findViewById(R.id.postarideButton);
    }
    
    private void addWidgetListeners() {
    	RadioGroupListener rListener = new RadioGroupListener();
    	mRideResponseGroup.setOnCheckedChangeListener(rListener);
    	PostarideButtonListener pListener = new PostarideButtonListener();
    	mPostRideButton.setOnClickListener(pListener);
    }
}